<?php

include_once("interface_conciergeremote.php");


class ConciergeRemote implements ConciergeRemoteInterface {
	private $concierge;

	public function __construct(&$concierge) {
		$this->concierge = $concierge;
	}
	
	public function registerPrincipal($name, $key, $callback_url) {
		return $this->concierge->registerPrincipal($name, $key, $callback_url);
	}
	
	public function unregisterPrincipal($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterPrincipal($name);
		}
		else return FALSE;
	}
	
	public function authenticatePrincipal($name, $key) {
		return $this->concierge->authenticatePrincipal($name, $key);
	}
	
	private function csvToArr(&$csv) {
		$arr = explode(",", $csv);
		$count = count($arr);
		for ($i = 0; $i < $count; $i++) {
			$arr[$i] = trim(strtolower($arr[$i]));
		}
		return $arr;
	}
	
	public function registerTagInterest($name, $key, $tags_commaseparated) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->registerTagInterest($name, $this->csvToArr($tags_commaseparated));
		}
		else return FALSE;

	}
	
	public function unregisterTagInterest($name, $key, $tags_commaseparated) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterTagInterest($name, $this->csvToArr($tags_commaseparated));
		}
		else return FALSE;
	}
	
	public function unregisterAllTagInterests($name, $key)  {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterAllTagInterests($name);
		}
		else return FALSE;
	}
	
	public function getTagInterests($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->getTagInterests($name);
		}
		else return FALSE;
	}
	
	
	public function registerGlobalInterest($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->registerGlobalInterest($name);
		}
		else return FALSE;
	}
	
	public function unregisterGlobalInterest($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterGlobalInterest($name);
		}
		else return FALSE;
	}
	
	
	public function registerPrincipalInterest($name, $key, $other_name) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->registerPrincipalInterest($name, $other_name);
		}
		else return FALSE;
	}
	
	public function getPrincipalInterests($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->getPrincipalInterests($name);
		}
		else return FALSE;
	}
	
	public function unregisterPrincipalInterest($name, $key, $other_name) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterPrincipalInterest($name, $other_name);
		}
		else return FALSE;
	}
	
	public function unregisterAllPrincipalInterests($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterAllPrincipalInterests($name);
		}
		else return FALSE;
	}
	
	
	public function unregisterAllInterests($name, $key) {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->unregisterAllInterests($name);
		}
		else return FALSE;
	}
	
	
	public function postMessage($sender_name, $sender_key, $content, $tags_commaseparated) {
		if($this->concierge->authenticatePrincipal($sender_name, $sender_key)) {
			return $this->concierge->postMessage($sender_name, $content, $this->csvToArr($tags_commaseparated));
		}
		else return FALSE;
	}
	

	public function getPrincipalInterestStream($name, $key, $since = 0, $limit = 1000)  {
		if($this->concierge->authenticatePrincipal($name, $key)) {
			return $this->concierge->getPrincipalInterestStream($name, $since, $limit);
		}
		else return FALSE;
	}
	
	public function getPrincipalStream($name, $since = 0, $limit = 1000)  {
		return $this->concierge->getPrincipalStream($name, $since, $limit);
	}
	
	public function getGlobalStream($since = 0, $limit = 1000)  {
		return $this->concierge->getGlobalStream($since, $limit);
	}
	
	public function getTaglistStream($tags_commaseparated, $since = 0, $limit = 1000)   {
		return $this->concierge->getTaglistStream($this->csvToArr($tags_commaseparated), $since, $limit);
	}
	
}


?>
